package com.rnkrsoft.suyan.config.server.ajax.executor;


import com.rnkrsoft.suyan.config.server.ajax.config.AjaxConfig;

import javax.doc.DocScanner;
import javax.doc.runtime.RuntimeDocScanner;
import java.util.HashMap;
import java.util.Map;

/**
 * Ajax执行器工厂
 */
public class AjaxExecutorFactory {
    private static final Map<ExecutorType, AjaxExecutor> CACHE = new HashMap<>();
    public static AjaxExecutor getInstance(AjaxConfig ajaxConfig){
        ExecutorType type = ExecutorType.valueOf(ajaxConfig.getExecuteType());
        AjaxExecutor ajaxExecutor = CACHE.get(type);
        if (ajaxExecutor == null){
           synchronized (AjaxExecutorFactory.class){
               ajaxExecutor = CACHE.get(type);
               if (ajaxExecutor == null){
                   if (type == ExecutorType.LOCAL) {
                       ajaxExecutor= new LocalAjaxExecutor(ajaxConfig);
                   }else if (type == ExecutorType.SPRING){
                       ajaxExecutor= new SpringAjaxExecutor(ajaxConfig);
                   }else {
                       ajaxExecutor= new LocalAjaxExecutor(ajaxConfig);
                   }
                   CACHE.put(type, ajaxExecutor);
               }
           }
        }
        return ajaxExecutor;
    }

}
